home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Sample Code / Networking / OT PAPServerSample / PAPServerSample.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-06  |  9.3 KB  |  265 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        PAPServerSample.h
  3.  
  4.     Contains:    headers, defines for the PAPServerSample.c file
  5.  
  6.     Written by:    Rich Kubota
  7.  
  8.     Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.     To Do:
  13.  
  14. */
  15.  
  16. #ifndef __PAPSERVERSAMPLE__
  17. #define __PAPSERVERSAMPLE__
  18.  
  19.  
  20. #ifndef __CONDITIONALMACROS__
  21. #include <ConditionalMacros.h>
  22. #endif
  23.  
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27.  
  28. #if PRAGMA_ALIGN_SUPPORTED
  29. #pragma options align=mac68k
  30. #endif
  31.  
  32. #if PRAGMA_IMPORT_SUPPORTED
  33. #pragma import on
  34. #endif
  35.  
  36. #include <stdio.h>
  37. #include <Types.h>
  38. #include <Memory.h>
  39. #include <Resources.h>
  40. #include <Events.h>
  41. #include "OpenTransport.h"        // open transport files    
  42. #include "OpenTptAppleTalk.h"    
  43.  
  44. #define SHOW_DEBUG_FLOW        1    // enable display of DebugStr showing program flow
  45.  
  46. #if SHOW_DEBUG_FLOW
  47. #define    DO_DEBUG_LOG        0    // enable a debug log at the beginning
  48. #endif
  49.  
  50. // defines for the STR# resource
  51. #define kServerStrID    1000    // STR# resource ID for the PAP Server Sample strings
  52.  
  53. #define kOTVersion111    0x01118000
  54. #define kOTVersion120    0x01208000
  55.  
  56. enum {
  57.     kServerNBPStrID    = 1,
  58.     kIdleStrID,
  59.     kBusyStrID
  60. };
  61.  
  62. #define kZeroQLen        0
  63. #define kDynamicSocket    0
  64. #define kATPType        3
  65. #define TIMEOUT            25         // seconds
  66. #define kMaxHandoffEPs    5        // maximum number of handoff endpoints supported by this sample
  67.  
  68. #define kDITop            0x0050        /* kTopLeft - for positioning the Disk
  69.                                                Initialization dialogs. */
  70. #define kDILeft            0x0070
  71.  
  72. #define kNumBuffers        25        // initial number of packet buffers to allocate
  73. #define kUserByteSize    4
  74. #define    kPAPDataSize    32768    // if we can, collect 16K of data at a time        
  75.  
  76. // defines for gFlags bits
  77. #define OTActiveFlag        0
  78. #define    dumpPktsFlag        1
  79. #define BufsInitdFlag        4
  80. #define InBackGndFlag        5
  81. #define BuffsHeldFlag        6
  82. #define CheckOptFlag        7
  83. #define StatusBusyFlag        8
  84. #define StatusIdleFlag        9
  85.  
  86. // flags macros for setting, testing and clearing the gFlag bits
  87. #define SetOTActiveFlag(flags)        ((flags) |= 1 << OTActiveFlag)
  88. #define ClrOTActiveFlag(flags)        ((flags) &= (-1 ^ (1 << OTActiveFlag)))
  89. #define TstOTActiveFlag(flags)        (((flags) & (1 << OTActiveFlag)) != 0)
  90.  
  91. #define SetdumpPktsFlag(flags)        ((flags) |= 1 << dumpPktsFlag)
  92. #define ClrdumpPktsFlag(flags)        ((flags) &= (-1 ^ (1 << dumpPktsFlag)))
  93. #define TstdumpPktsFlag(flags)        (((flags) & (1 << dumpPktsFlag)) != 0)
  94.  
  95. #define SetBufsInitdFlag(flags)        ((flags) |= 1 << BufsInitdFlag)
  96. #define ClrBufsInitdFlag(flags)        ((flags) &= (-1 ^ (1 << BufsInitdFlag)))
  97. #define TstBufsInitdFlag(flags)        (((flags) & (1 << BufsInitdFlag)) != 0)
  98.  
  99. #define SetInBackGndFlag(flags)        ((flags) |= 1 << InBackGndFlag)
  100. #define ClrInBackGndFlag(flags)        ((flags) &= (-1 ^ (1 << InBackGndFlag)))
  101. #define TstInBackGndFlag(flags)        (((flags) & (1 << InBackGndFlag)) != 0)
  102.  
  103. #define SetBuffsHeldFlag(flags)        ((flags) |= 1 << BuffsHeldFlag)
  104. #define ClrBuffsHeldFlag(flags)        ((flags) &= (-1 ^ (1 << BuffsHeldFlag)))
  105. #define TstBuffsHeldFlag(flags)        (((flags) & (1 << BuffsHeldFlag)) != 0)
  106.  
  107. #define SetCheckOptFlag(flags)        ((flags) |= 1 << CheckOptFlag)
  108. #define ClrCheckOptFlag(flags)        ((flags) &= (-1 ^ (1 << CheckOptFlag)))
  109. #define TstCheckOptFlag(flags)        (((flags) & (1 << CheckOptFlag)) != 0)
  110.  
  111. #define SetStatusBusyFlag(flags)    ((flags) |= 1 << StatusBusyFlag)
  112. #define ClrStatusBusyFlag(flags)    ((flags) &= (-1 ^ (1 << StatusBusyFlag)))
  113. #define TstStatusBusyFlag(flags)    (((flags) & (1 << StatusBusyFlag)) != 0)
  114.  
  115. #define SetStatusIdleFlag(flags)    ((flags) |= 1 << StatusIdleFlag)
  116. #define ClrStatusIdleFlag(flags)    ((flags) &= (-1 ^ (1 << StatusIdleFlag)))
  117. #define TstStatusIdleFlag(flags)    (((flags) & (1 << StatusIdleFlag)) != 0)
  118.  
  119. // defines for the semaphore bits
  120. #define kInListenLoop        0        // this bit used with OTAtomicSetBit to control re-entrancy into the DoListenAccept procedure
  121. #define kInRcvDataFlag        1        // used with OTAtomic calls to check whether in DoReceive call
  122.  
  123. // defines for flags bits
  124. #define EPActiveFlag        0        // indicates that the endpoint is active
  125. #define EPBoundFlag            1        // indicates the endpoint is bound
  126. #define EPListenFlag        2        // indicates that the endpoint has processed a listen request
  127. #define EPBusyFlag            3        // used with handoff endpoint to indicate it has accepted 
  128.                                     // a handoff endpoint
  129. #define ListenerSavedFlag    4        // a listener has been identified and saved locally
  130. #define PassconFlag            6        // the passive connection has completed
  131. #define EOMOnFlag            7        // EOM option enabled
  132. #define ListenPendFlag        10
  133. #define AcceptPendFlag        11
  134. #define    TempFileFlag        12        // indicates that a temp file has been opened for data to this endpoint
  135. #define InPSQueryFlag        13        // indicates that the endpoint is currently processing a PS query
  136. #define HasDataFlag            14        // indicates that there is more to read for this endpoint
  137. #define OrdDisconFlag        15        // indicates that the server received an orderly discon event
  138.  
  139. // flags macros for setting, testing and clearing the flag bits
  140. #define SetEPActiveFlag(flags)        ((flags) |= 1 << EPActiveFlag)
  141. #define ClrEPActiveFlag(flags)        ((flags) &= (-1 ^ (1 << EPActiveFlag)))
  142. #define TstEPActiveFlag(flags)        (((flags) & (1 << EPActiveFlag)) != 0)
  143.  
  144. #define SetEPBoundFlag(flags)        ((flags) |= 1 << EPBoundFlag)
  145. #define ClrEPBoundFlag(flags)        ((flags) &= (-1 ^ (1 << EPBoundFlag)))
  146. #define TstEPBoundFlag(flags)        (((flags) & (1 << EPBoundFlag)) != 0)
  147.  
  148. #define SetEPListenFlag(flags)        ((flags) |= 1 << EPListenFlag)
  149. #define ClrEPListenFlag(flags)        ((flags) &= (-1 ^ (1 << EPListenFlag)))
  150. #define TstEPListenFlag(flags)        (((flags) & (1 << EPListenFlag)) != 0)
  151.  
  152. #define SetEPBusyFlag(flags)        ((flags) |= 1 << EPBusyFlag)
  153. #define ClrEPBusyFlag(flags)        ((flags) &= (-1 ^ (1 << EPBusyFlag)))
  154. #define TstEPBusyFlag(flags)        (((flags) & (1 << EPBusyFlag)) != 0)
  155.  
  156. #define SetListenerSavedFlag(flags)    ((flags) |= 1 << ListenerSavedFlag)
  157. #define ClrListenerSavedFlag(flags)    ((flags) &= (-1 ^ (1 << ListenerSavedFlag)))
  158. #define TstListenerSavedFlag(flags)    (((flags) & (1 << ListenerSavedFlag)) != 0)
  159.  
  160. #define SetPassconFlag(flags)        ((flags) |= 1 << PassconFlag)
  161. #define ClrPassconFlag(flags)        ((flags) &= (-1 ^ (1 << PassconFlag)))
  162. #define TstPassconFlag(flags)        (((flags) & (1 << PassconFlag)) != 0)
  163.  
  164. #define SetEOMOnFlag(flags)            ((flags) |= 1 << EOMOnFlag)
  165. #define ClrEOMOnFlag(flags)            ((flags) &= (-1 ^ (1 << EOMOnFlag)))
  166. #define TstEOMOnFlag(flags)            (((flags) & (1 << EOMOnFlag)) != 0)
  167.  
  168. #define SetListenPendFlag(flags)    ((flags) |= 1 << ListenPendFlag)
  169. #define ClrListenPendFlag(flags)    ((flags) &= (-1 ^ (1 << ListenPendFlag)))
  170. #define TstListenPendFlag(flags)    (((flags) & (1 << ListenPendFlag)) != 0)
  171.  
  172. #define SetAcceptPendFlag(flags)    ((flags) |= 1 << AcceptPendFlag)
  173. #define ClrAcceptPendFlag(flags)    ((flags) &= (-1 ^ (1 << AcceptPendFlag)))
  174. #define TstAcceptPendFlag(flags)    (((flags) & (1 << AcceptPendFlag)) != 0)
  175.  
  176. #define SetTempFileFlag(flags)        ((flags) |= 1 << TempFileFlag)
  177. #define ClrTempFileFlag(flags)        ((flags) &= (-1 ^ (1 << TempFileFlag)))
  178. #define TstTempFileFlag(flags)        (((flags) & (1 << TempFileFlag)) != 0)
  179.  
  180. #define SetInPSQueryFlag(flags)        ((flags) |= 1 << InPSQueryFlag)
  181. #define ClrInPSQueryFlag(flags)        ((flags) &= (-1 ^ (1 << InPSQueryFlag)))
  182. #define TstInPSQueryFlag(flags)        (((flags) & (1 << InPSQueryFlag)) != 0)
  183.  
  184. #define SetHasDataFlag(flags)        ((flags) |= 1 << HasDataFlag)
  185. #define ClrHasDataFlag(flags)        ((flags) &= (-1 ^ (1 << HasDataFlag)))
  186. #define TstHasDataFlag(flags)        (((flags) & (1 << HasDataFlag)) != 0)
  187.  
  188. #define SetOrdDisconFlag(flags)        ((flags) |= 1 << OrdDisconFlag)
  189. #define ClrOrdDisconFlag(flags)        ((flags) &= (-1 ^ (1 << OrdDisconFlag)))
  190. #define TstOrdDisconFlag(flags)        (((flags) & (1 << OrdDisconFlag)) != 0)
  191.  
  192.  
  193. enum {
  194.     kLookingForEndStr = 1,
  195.     kLookingForQueryStr,
  196.     kLookingForDefaultResponse,
  197.     kLookingForEOFStr
  198. };
  199.  
  200. enum {
  201.     kSetBusyStr = 1,
  202.     kSetIdleStr,
  203.     kAcceptOption,
  204.     kDeclineOption,
  205.     kQuitTest
  206. };    
  207.  
  208.  
  209. /*******************************************************************************
  210. ** Structures
  211. ********************************************************************************/
  212. typedef struct MyEndpointRef MyEndpointRef;
  213.  
  214. typedef struct 
  215. {
  216.         OTLink        fLink;                        // first field standard for OTLink list
  217.         OTFlags        flags;
  218.         MyEndpointRef *theEp;                    // save the endpoint ref associated with the endpoint
  219.         UInt32        lastPos;                    // last scanned position in the buffer
  220.         UInt32        numBytes;                    // numBytes in this packet
  221.         OTTimeStamp    timeStamp;                    // timestamp of this packet
  222.         UInt8        data[kPAPDataSize];            // data bytes of packet
  223. } PacketBuffer;
  224.  
  225. typedef PacketBuffer *PacketPtr;
  226.  
  227. struct MyEndpointRef
  228. {
  229.     EndpointRef        ep;
  230.     UInt32            flags;
  231.     OTLIFO            *usedQ;                    // ptr to incoming packet queue for this connection
  232.     PacketPtr        prevPtr;                // used while processing a postscript
  233.                                             // query where we have to save the previous packet
  234.                                             // in order to complete processing of queries.
  235.     OTTimeStamp        timeDataIn;                // timestamp of first incoming packet
  236.     OTTimeStamp     timeDataEnd;            // timestamp of last incoming packet
  237.     OTTimeStamp        timerDog;                // timestamp of most recent packet
  238.  
  239.     UInt32            numBytesIn;                // number of bytes received for a connection
  240.     UInt16            psState;                // state while processing a postscript query
  241.     short            fRefNum;                // file ref num of temp file associated
  242.                                             //    with this endpoint
  243.     UInt8            semaphore;
  244.     UInt8            dummy;
  245. };
  246.  
  247.  
  248. // Prototypes
  249. extern void DoValueBreak(long value, const char* message);
  250.  
  251.  
  252. #if PRAGMA_IMPORT_SUPPORTED
  253. #pragma import off
  254. #endif
  255.  
  256. #if PRAGMA_ALIGN_SUPPORTED
  257. #pragma options align=reset
  258. #endif
  259.  
  260. #ifdef __cplusplus
  261. }
  262. #endif
  263.  
  264. #endif /* __PAPSERVERSAMPLE__ */
  265.